package com.czy.owner.ui.workorder.orderviewholder;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.MyOrderModel;
import com.czy.owner.entity.WorkOrderModel;
import com.czy.owner.ui.workorder.PaidEndOfPaymentActivity2;
import com.czy.owner.utils.DecimalUtil;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.widget.CountdownView;
import com.easyrecycleview.adapter.BaseViewHolder;

/**
 * Created by hedepu on 2017-08-28
 */

public class OrderPendingPaymentBanlanceViewHolder extends BaseViewHolder<WorkOrderModel> {
    private TextView btn_order_paid, tv_order_number, tv_order_state, tv_order_num, tv_store_name, tv_order_service_time, tv_order_commodity_project, tv_order_item, tv_order_custom_commodity_project, tv_order_dingjing_title, tv_order_jishi, tv_order_dingjing;

    private Context context;
    //    private Button btn_order_paid;
    private LinearLayout linear_order_num;

    public OrderPendingPaymentBanlanceViewHolder(ViewGroup parent, Context ctx) {
        super(parent, R.layout.item_order_pending_payment_banlance);
        tv_order_number = $(R.id.tv_order_number);
        tv_order_state = $(R.id.tv_order_state);
        tv_order_num = $(R.id.tv_order_num);
        tv_store_name = $(R.id.tv_store_name);
        linear_order_num = $(R.id.linear_order_num);
        tv_order_service_time = $(R.id.tv_order_service_time);
        tv_order_commodity_project = $(R.id.tv_order_commodity_project);
        tv_order_item = $(R.id.tv_order_item);
        tv_order_custom_commodity_project = $(R.id.tv_order_custom_commodity_project);
        tv_order_jishi = $(R.id.tv_order_jishi);
        tv_order_dingjing = $(R.id.tv_order_dingjing);
        btn_order_paid = $(R.id.btn_order_paid);
        tv_order_dingjing_title = $(R.id.tv_order_dingjing_title);

        this.context = ctx;
    }

    @Override
    public void setData(final WorkOrderModel model) {
        super.setData(model);
        tv_store_name.setText(model.getStoreName());
        tv_order_number.setText("工单编号: " + model.getOrderNumber());
        tv_order_service_time.setText(TimeUtils.formatTimeDifference2(model.getOpenTime()));
        if (model.getStoreBookingNumber() != null && !model.getStoreBookingNumber().isEmpty()) {
            if (linear_order_num.getVisibility() == View.GONE)
                linear_order_num.setVisibility(View.VISIBLE);
            tv_order_num.setText(model.getStoreBookingNumber());
        } else {
            if (linear_order_num.getVisibility() == View.VISIBLE)
                linear_order_num.setVisibility(View.GONE);
        }
        tv_order_item.setText(StringUtils.getString(model.getAllServiceName(), "无"));
        tv_order_commodity_project.setText(StringUtils.getString(model.getGoodsName(), "无"));
        tv_order_custom_commodity_project.setText(StringUtils.getString(model.getAllCustomName(), "无"));
        tv_order_jishi.setText(model.getLicenseNumber() + "  " + model.getChName());
//        tv_order_dingjing.setText("¥" + DecimalUtil.formatNum(model.getPayAmount()) + "");
        tv_order_dingjing.setText("¥" + DecimalUtil.formatNum(model.getTotalPrice()));
        if (StringUtils.isEmpty(model.getStoreBookingNumber())) {

//            tv_order_dingjing_title.setText("待付金额");
            tv_order_state.setText("待付金额");
        } else {
//            tv_order_dingjing_title.setText("待付尾款");
            tv_order_state.setText("待付尾款");
        }
        btn_order_paid.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent ti = new Intent(context, PaidEndOfPaymentActivity2.class);
                ti.putExtra("orderNumber", model.getOrderNumber());
                ti.putExtra("storeId", model.getStoreId());
                ti.putExtra("userOrderId", model.getUserOrderId());
                ti.putExtra("isbespoke", !StringUtils.isEmpty(StringUtils.getString(model.getStoreBookingNumber())));
                context.startActivity(ti);
            }
        });
    }
}
